//
//  JSONPath.m
//  oos4ios-client
//
//  Created by Pablo Gonzalez on 6/8/11.
//  Copyright 2011 11870.com. All rights reserved.
//

#import "NSDictionary+Path.h"
#import "../External/JSON/JSON.h"

@implementation NSDictionary (Path)

- (id) objectForPath: (NSString *) path
{
    id result = nil;
    NSUInteger slash = [path rangeOfString: @"/"].location;
    if (slash != NSNotFound) {
        NSString *component = [path substringToIndex: slash];
        path = [path substringFromIndex: slash + 1];
        id child = [self objectForKey: component];
        if ([child isKindOfClass: [NSDictionary class]]) {
            result = [(NSDictionary *)child objectForPath: path]; 
        }
    } else if (path.length > 0) {
        result = [self objectForKey: path];
    }
    return result;
}

@end
